﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Microsoft.Practices.EnterpriseLibrary.Validation.Configuration;

namespace ElValWeb.ValidatorClientAdapters {
    public class RangeValidatorClientAdapter : BaseClientAdapter<RangeValidatorData> {
        
        public RangeValidatorClientAdapter(RangeValidatorData validatorData) : base(validatorData) {
        }

        public override IEnumerable<ModelClientValidationRule> GetClientRules(Type ownerType) {


            if (!ownerType.In(typeof(Int16), typeof(Int32), typeof(Int64), typeof(Char), typeof(Single), typeof(Double), typeof(Decimal))) {
                return new ModelClientValidationRule[] { };
            }

            var rule = new ModelClientValidationRule {
                ErrorMessage = ValidatorData.GetMessageTemplate(),
                ValidationType = "rangeValidatorComplex"
            };

            rule.ValidationParameters["lowerBound"] = ValidatorData.LowerBound;
            rule.ValidationParameters["lowerBoundType"] = (int)ValidatorData.LowerBoundType ;
           
            rule.ValidationParameters["upperBound"] = ValidatorData.UpperBound;
            rule.ValidationParameters["upperBoundType"] = (int)ValidatorData.UpperBoundType + 3;
            

            return new [] { Negate(rule, ValidatorData.Negated) }; 
        }
    }

    
}
